extends Node2D


# Declare member variables here. Examples:
# var a = 2
# var b = "text"

var room_postfix = "_incoming"
var incoming_room_alias

var client: Matrix= Matrix.new()
onready var status_label = find_node("STATUS")

# Called when the node enters the scene tree for the first time.
func _ready():
	add_child(client)	
	pass # Replace with function body.

func _process(delta):
	if status_label.active:
		var string: String = client.fetch_one()
		if 'boom' in string.to_lower():
			print("MAIN: BOOM")
			$playscene/spawner.spawn()

func start_game():
	status_label.active = true
	status_label.visible = true
	var incoming_room_name_partial = client.get_username()+room_postfix
	client.create_if_not(incoming_room_name_partial)
	incoming_room_alias = "#"+incoming_room_name_partial+":"+client.get_homeserver()
	print("incoming hyperpackages room is ", incoming_room_alias)
	var joinres = client.join(incoming_room_alias)
	if not joinres:
		print ("could not join our own room!")
		get_tree().quit()
	status_label.alias = incoming_room_alias
	status_label.id = joinres
	client.synchronize()
	var room_id = joinres
#	client.fetch_new(room_id)
	client.start_listen(room_id)

# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
#	pass
